home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
tpcmag.arc
/
FORMAT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-05-19
|
1KB
|
46 lines
Program FormatDemo ;
{from PC Magazine page 267 dated June 10, 1986 by Michael G. Weiss
of Dallas TX.
Routines reformat numbers by adding commas or providing parens around negative numbers.
Works with version 2 TurboPascal.
}
type Str32 = string[32];
var Number : real;
function Comma (Number:real; Field:integer; Dec:integer) : Str32 ;
var hold : str32;
i : integer;
begin
str(number:field:dec, hold);
if dec > 0 then dec := dec + 1;
for i := 1 to (field - dec - 3) do
if ((field - dec - i) mod 3 = 0) and (hold[i] <> ' ')
and (hold[i] <> '-') then begin
delete(hold,1,1);
insert(',',hold,i);
end;
comma := hold;
end; { function Comma (Number:real; Field;integer; Dec:integer) }
function PosNeg (number:real; field:integer; round:integer): str32;
var hold : str32;
begin
hold := comma (number,field,round);
delete (hold,1,1);
if number < 0 then begin
posneg := hold + ')';
posneg[pos('-',hold)] := '(';
end
else posneg := hold + ' ';
end; { function PosNeg (number:real; field:integer; round:integer) }
begin {main}
while (true) do begin
write('Enter a real number: '); readln (number);
writeln(comma(number,16,0));
writeln(comma(number,16,2));
writeln(posneg(number,16,0));
writeln(posneg(number,16,2));
end;
END.